package com.tanhua.server.controller;

import com.tanhua.model.vo.CommentVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 圈子互动（动态评论表）控制层
 */
@RestController
@RequestMapping("/comments")
public class CommentController {


    @Autowired
    private CommentService commentService;

    /**
     *   评论分页列表
     *   movementId:动态表主键id
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity findPageComment(@RequestParam(value = "page",defaultValue = "1") Long page, @RequestParam(value = "pagesize",defaultValue = "10") Long pagesize, String movementId){
        PageResult<CommentVo> pageResult = commentService.findPageComment(page,pagesize,movementId);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 评论-提交(动态评论)
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity addComment(@RequestBody Map<String,String> params){
        String publishId = params.get("movementId");//动态编号
        String content = params.get("comment");//动态评论内容
        commentService.addComment(publishId,content);
        return ResponseEntity.ok(null);
    }
}
